#include "File.h"
#include "cstring"
#include <string>
#include <cstdio>
#include <iostream>

File::File( std::string IPAddress ,std::string Filepath, std::string Filename, std::string TimeStamp, int ID , bool isSysFile )
{

	m_IPAddress = IPAddress;
	m_path		= Filepath;
	m_Name		= Filename;
	m_bCached	= false;
	m_isSysFile	= isSysFile;
	m_ID		= ID;

	struct tm * MyTime ;
	time( &m_TimeStamp );

	MyTime =  localtime( &m_TimeStamp );
	sscanf( TimeStamp.c_str(),"%d:%d:%d %d/%d/%d"
							 ,&( MyTime->tm_hour)
							 ,&( MyTime->tm_min)
							 ,&( MyTime->tm_sec)
							 ,&( MyTime->tm_mon)
							 ,&( MyTime->tm_mday)
							 ,&( MyTime->tm_year ) );

	MyTime->tm_year -= 1900 ;
	m_TimeStamp = mktime( MyTime );
};

bool	File::Authenticate( std::string IPAddress )
{

	if( m_isSysFile )
	{
		//All can access System files
		return true;
	}
	else
	{
		return ( IPAddress == m_IPAddress );
	}
};

bool	File::UpdateFile( std::string strNewTime )
{
	struct tm * MyTime ;
	time( &m_TimeStamp );

	MyTime =  localtime( &m_TimeStamp );
	sscanf( strNewTime.c_str(),"%d:%d:%d %d/%d/%d"
							 ,&( MyTime->tm_hour)
							 ,&( MyTime->tm_min)
							 ,&( MyTime->tm_sec)
							 ,&( MyTime->tm_mon)
							 ,&( MyTime->tm_mday)
							 ,&( MyTime->tm_year ) );

	MyTime->tm_year -= 1900 ;
	m_TimeStamp = mktime( MyTime );

	return true;
};
